package com.imooc.course.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.fastjson.JSON;
import com.imooc.course.dto.CourseDTO;
import com.imooc.course.service.ICourseService;
import com.imooc.thrift.user.dto.UserDTO;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author LiJian
 * @date 2022/10/25
 */
@RestController
@RequestMapping("/course")
public class CourseController {
    @DubboReference
    private ICourseService courseService;
    @GetMapping("/courseList")
    public String courseDTOList(HttpServletRequest request){
        UserDTO userDTO = (UserDTO)request.getAttribute("user");
        System.out.println("user is :"+JSON.toJSONString(userDTO));
        List<CourseDTO> courseDTOS = courseService.courseList();
        return JSON.toJSONString(courseDTOS);
    }
}
